package com.alvin.abp.domain;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.GrantedAuthorityImpl;
import org.springframework.security.core.userdetails.UserDetails;

import com.alvin.abp.common.constant.UserRoleType;
/**
 * 
 * Based user entity for alvin member.
 * @author <a href="mailto:rex2.mj@gmail.com">Leo Meng</a>
 * @date $Date: Mar 25, 2013 $
 */
public class AlvinUser extends AbstractEntity implements UserDetails {
	

	public static final Long DEFAULT_SA_ID=1L;
	private static final long serialVersionUID = 1L;
	
	private String userName;
	private Gender gender;
	private String mobile;
	private Date babyBirth;
	private String password;
	private String confirmPassword;
	private UserRoleType role;
	private BigDecimal balance;
	private List<Record> records;
	
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public Gender getGender() {
		return gender;
	}
	public void setGender(Gender gender) {
		this.gender = gender;
	}	
	public String getMobile() {
		return mobile;
	}
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	public Date getBabyBirth() {
		return babyBirth;
	}
	public void setBabyBirth(Date babyBirth) {
		this.babyBirth = babyBirth;
	}	
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getConfirmPassword() {
		return confirmPassword;
	}
	public void setConfirmPassword(String confirmPassword) {
		this.confirmPassword = confirmPassword;
	}	
	public UserRoleType getRole() {
		return role;
	}
	public void setRole(UserRoleType role) {
		this.role = role;
	}
	public BigDecimal getBalance() {
		return balance;
	}
	public void setBalance(BigDecimal balance) {
		this.balance = balance;
	}	
	/* (non-Javadoc)   
	 * @see org.springframework.security.userdetails.UserDetails#getAuthorities()  
	 */
	@Override
	public Collection<GrantedAuthority> getAuthorities() {
		List<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>(UserRoleType.values().length);
    	for(UserRoleType role : UserRoleType.values()) {
    		grantedAuthorities.add(new GrantedAuthorityImpl(role.getName()));
    	}
        return grantedAuthorities;
	}
	/* (non-Javadoc)   
	 * @see org.springframework.security.userdetails.UserDetails#getUsername()  
	 */
	@Override
	public String getUsername() {
		return mobile;
	}
	/* (non-Javadoc)   
	 * @see org.springframework.security.userdetails.UserDetails#isAccountNonExpired()  
	 */
	@Override
	public boolean isAccountNonExpired() {
		// TODO Auto-generated method stub
		return true;
	}
	/* (non-Javadoc)   
	 * @see org.springframework.security.userdetails.UserDetails#isAccountNonLocked()  
	 */
	@Override
	public boolean isAccountNonLocked() {
		// TODO Auto-generated method stub
		return true;
	}
	/* (non-Javadoc)   
	 * @see org.springframework.security.userdetails.UserDetails#isCredentialsNonExpired()  
	 */
	@Override
	public boolean isCredentialsNonExpired() {
		// TODO Auto-generated method stub
		return true;
	}
	/* (non-Javadoc)   
	 * @see org.springframework.security.userdetails.UserDetails#isEnabled()  
	 */
	@Override
	public boolean isEnabled() {
		return true;
	}
	public List<Record> getRecords() {
		return records;
	}
	public void setRecords(List<Record> records) {
		this.records = records;
	}
	
}
